﻿namespace EasyDDD.AdminModule.Application.CommandsSysAdminRole
{
    public record SysAdminRoleDeleteCommand : ICommand
    {
        public Guid Id { get; set; }
        public Guid RowVersion { get; set; } = default!;
    }
    //public class SysAdminRoleDeleteCommandValidator : AbstractValidator<SysAdminRoleDeleteCommand>
    //{
    //    public SysAdminRoleDeleteCommandValidator(Repository.SysAdminRoleRepository repository)
    //    {
    //        var query = repository.AsQueryable();
    //        RuleFor(x => x.Id).Must((id) => query.Any(e => e.Id == id)).WithMessage("不存在该RoleClaim");
    //    }
    //}
    public class SysAdminRoleDeleteHandler(
        Repository.SysAdminRoleRepository repository,
        ILogger<SysAdminRoleDeleteHandler> logger)
        : ICommandHandler<SysAdminRoleDeleteCommand>
    {
        public async Task Handle(SysAdminRoleDeleteCommand request, CancellationToken cancellationToken)
        {
            logger.LogDebug("命令 SysAdminRoleDeleteHandler");
            var entity = await repository.GetAsync(request.Id, request.RowVersion);
            entity.Delete();
        }
    }
}
